<script>
    
    let template = require('html!./index.html')
    import VitaTable from '../components/table.vue'
    import _ from 'lodash'
    import moment from 'moment'
    import {Promise} from 'es6-promise'

    export default {

      template,

      components: { VitaTable },

      data() {
        return {
    
          gridTitle: 'Vita-Grid',

          gridColumns: ['编号', '日期', '顾客', '状态', '价格'],

          searchQuery: '',


          formatServerSideData(responseData, cb) {
             let list = _.map(responseData.data, function(item) {
              item.el = [
              '<a>#' + item.id + '</a>',
              moment(item.date).format('YYYY/MM/DD'),
              item.customer,
              '<span class="label label-success">' + item.status + '</span>',
              '$ ' + item.price,
              [{
                event: 'addUser',
                el: '<a class="table-link"><span class="fa-stack"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-search-plus fa-stack-1x fa-inverse"></i></span></a>'
              }, {
                event: 'addRoom',
                el: '<a class="table-link">删除</a>'
              }]
              ]
              return item
            })
            // return Promise.resolve(formatData)
            // return {
            //   list: list,
            //   length: 10,
            //   totalSize: 512
            // }
            responseData.data = list
            cb(responseData)
          }
        }
      },

      events: {
        'vita-table:addUser': function(params) {
          console.log('修改', params.id)
        }, 
        'vita-table:addRoom': function(params) {
          console.log(params.price)
        }
      },

      computed: {
        renderData() {
          let mockDatas = []
          for (let i = 0;i < 50;i++) {
            let mockData = {
              id: i,
              date: +new Date(),
              customer: 'Robert De Niro',
              status: 'Completed',
              price: 8990 + i
            }
            mockDatas.push(mockData)
          }

          return _.map(mockDatas, function(item) {
            item.el = [
            '<a>#' + item.id + '</a>',
            moment(item.date).format('YYYY/MM/DD'),
            item.customer,
            '<span class="label label-success">' + item.status + '</span>',
            '$ ' + item.price,
            [{
              event: 'addUser',
              el: '<a class="table-link"><span class="fa-stack"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-search-plus fa-stack-1x fa-inverse"></i></span></a>'
            }, {
              event: 'addRoom',
              el: '<a class="table-link">删除</a>'
            }]
            ]
            return item
          })

        }, 

      }

    }

</script>